package com.jason.mail;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class MailUtil {

    private static Logger logger = LoggerFactory.getLogger(MailUtil.class);

    public static boolean sendSimpleMail(String[] targetAddress, String subject, String content) {
        try {
            logger.info("sendSimpleMail,targetAddress:{},subject:{},content:{}",targetAddress,subject,content);
            MailSenderInfo mailSenderInfo = new MailSenderInfo(targetAddress, subject, content, null);
            MailSender.sendMail(mailSenderInfo);
        } catch (Exception e) {
            logger.error("发送邮件异常。", e);
            return false;
        }
        return true;
    }

    public static boolean sendSimpleMail(String[] targetAddress, String[] ccAddresses, String subject, String content) {
        try {
            logger.info("sendSimpleMail,targetAddress:{},ccAddresses:{},subject:{},content:{}",targetAddress,ccAddresses,subject,content);
            MailSenderInfo mailSenderInfo = new MailSenderInfo(targetAddress, ccAddresses, subject, content, null);
            MailSender.sendMail(mailSenderInfo);
        } catch (Exception e) {
            logger.error("发送邮件异常。", e);
            return false;
        }
        return true;
    }


    public static void main(String[] args) {
        String [] targetAddress = {"wangj523@163.com"};
        String subject = "郵箱測試";
        String content = "你好，郵箱服務測試邮箱";
        MailSenderInfo mailSenderInfo = new MailSenderInfo(targetAddress, subject, content, null);
        boolean b = MailSender.sendMail(mailSenderInfo);
        System.out.println(b);
    }


}
